<template>
	<view class="content">
		<!--顶部标签-->
		<view class="content_1">
			<view class="tab_view">
				<view class="tab_box" @click="changeTab(1)">
					<view :class="choosetab == 1 ? 'tab_name' : 'tab_name_none'">类型</view>
					<image class="tab_icon" src="../../../static/mine/downjiantou.svg"></image>
				</view>
				<view class="tab_box" @click="changeTab(2)">
					<view :class="choosetab == 2 ? 'tab_name' : 'tab_name_none'">年份</view>
					<image class="tab_icon" src="../../../static/mine/downjiantou.svg"></image>
				</view>
				<view class="tab_box" @click="changeTab(3)">
					<view :class="choosetab == 3 ? 'tab_name' : 'tab_name_none'">月份</view>
					<image class="tab_icon" src="../../../static/mine/downjiantou.svg"></image>
				</view>
			</view>
		</view>
		<!--账单详细-->
		<view class="content_2">
			<block v-for="(item_order, index_order) in orderList" :key='index_order'>
				<view class="order_view">
					<view class="line_2"></view>
					
					<view class="order_box">
						<view class="detail_name">交易类型</view>
						<view class="detail">{{item_order.point_cause}}</view>
					</view>
					<view class="order_box">
						<view class="detail_name">交易时间</view>
						<view class="detail">{{item_order.create_time}}</view>
					</view>
					<view class="order_box">
						<view class="detail_name">流水单号</view>
						<view class="detail">{{item_order.order_sn}}</view>
					</view>
					<view class="order_box">
						<view class="detail_name">变更积分</view>
						<view class="detail">{{item_order.symbol}}{{item_order.change_point}}</view>
					</view>
					<view class="order_box">
						<view class="detail_name">剩余积分</view>
						<view class="detail">{{item_order.surplus_point}}</view>
					</view>
					<view class="order_box">
						<view class="detail_name">备注</view>
						<view class="detail">无</view>
					</view>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
	import {Request} from '../../../utils/request.js';
	const app = getApp();
	export default {
		data() {
			return {
				choosetab: '1',
				orderList: [],
				//排序状态
				sortstate: '0',
			}
		},
		methods: {
			//升序方法
			compare: function(property) {
				console.log(property)
				return function(a, b) {
					var value1 = a[property];
					var value2 = b[property];
					return value1 - value2;
				}
			},
			//降序方法
			uncompare: function(property) {
				return function(a, b) {
					var value1 = a[property];
					var value2 = b[property];
					return value2 - value1;
				}
			},
			//tab切换
			changeTab: function(id) {
				this.choosetab = id
				if(id == 2) {
					if (this.sortstate == '0') {
						this.orderList.sort(this.compare('year'))
						this.sortstate = '1'
					} else {
						this.orderList.sort(this.uncompare('year'))
						this.sortstate = '0'
					}
				}
				if (id == 3) {
					if (this.sortstate == '0') {
						this.orderList.sort(this.compare('month'))
						this.sortstate = '1'
					} else {
						this.orderList.sort(this.uncompare('month'))
						this.sortstate = '0'
					}
				}
			}
		},
		onLoad() {
			//获取账单列表
			new Request('point/Get_User_Point_List/GetPointList').request(
				()=>{
					return 'POST'
				},
				()=>{
					return {
						openid: app.globalData.openid
					}
				},
				(res)=>{
					if (res.data.code == 1) {
						this.orderList = res.data.data
						this.orderList = this.orderList.map((item, index) =>{
							return {
								// bill_describe: item.bill_describe,
								// bill_type: item.bill_type,
								// id: item.id,
								// order_id: item.order_id,
								order_sn: item.refer_number,
								change_point: item.change_point,
								surplus_point: item.surplus_point,
								point_cause: item.point_cause,
								create_time: item.create_time,
								// pay_money: item.pay_money,
								// paytime: item.paytime,
								// status: item.status,
								month: item.create_time.slice(5,7),
								year: item.create_time.slice(0,4),
								symbol: item.point_add_reduce == 1 ? '+' : (item.point_add_reduce == 3 ? '+' : '-'),
							}
						})
						console.log(this.orderList)
					} else {
						uni.showToast({
							title: '没有积分明细',
							icon: 'none',
							position: 'center'
						})
					}
				}
			)
		}
	}
</script>

<style>
	page {
		background-color: #F9F9F9;
	}

	.content {
		padding-bottom: 190upx;
	}

	/*
		顶部标签样式
	*/
	.content_1 {
		margin-top: 40upx;
		padding-left: 40upx;
	}

	.tab_view {
		height: 40upx;
		display: flex;
		align-items: center;
	}

	.tab_box {
		height: 40upx;
		display: flex;
		align-items: center;
		margin-right: 80upx;
	}

	.tab_name {
		height: 40upx;
		line-height: 40upx;
		font-size: 28upx;
		color: #B3E9DC;
		margin-right: 10upx;
	}

	.tab_name_none {
		height: 40upx;
		line-height: 40upx;
		font-size: 28upx;
		color: #666666;
		margin-right: 10upx;
	}

	.tab_icon {
		height: 28upx;
		width: 28upx;
	}

	/**
	 * 账单详细样式
	 */

	.order_view {
		margin-top: 30upx;
		display: flex;
		flex-direction: column;
	}

	.line_2 {
		height: 20upx;
		background-color: #FFFFFF;
		margin-bottom: 20upx;
	}

	.order_box {
		height: 80upx;
		padding: 0upx 40upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.detail_name {
		height: 80upx;
		line-height: 80upx;
		font-size: 28upx;
		color: #999999;
	}

	.detail {
		height: 80upx;
		line-height: 80upx;
		font-size: 28upx;
		color: #999999;
	}
</style>
